# Makefile for the Era Astral mesh viewer tool
# Use GCC (G++) for both compiling and linking on Linux
# Use MinGW for compiling and linking on windows
# Use GCC (G++) for both compiling and linking on OSX

# C++ compiler
CXX = g++
# C++ compiler flags
CXXFLAGS = -Wall `sdl-config --cflags` -I../../ -D_GNU_SOURCE=1 -DHAVE_OPENGL
LINUXCXXFLAGS = -D_LINUX
WINCXXFLAGS = -D_WIN32 -Dmain=SDL_main
OSXCXXFLAGS = -D_OSX

# Linker
LD = g++
# Linker options
LINUXLDFLAGS = `sdl-config --libs` -lSDL_image -lGL -lGLU
WINDOWSLDFLAGS = `sdl-config --libs` -lSDL_image -lopengl32 -lglu32
OSXLDFLAGS = `sdl-config --libs`-lSDL_image -lGL -lGLU

# Remove command
RM = rm -f

# Name of final executable
LINUXPROG = MeshViewer
WINPROG = MeshViewer.exe
OSXPROG = MeshViewer

# Primary sources
SOURCES = main.cpp MeshViewer.cpp GUIMenu.cpp \
		  ../../CStaticMesh.cpp ../../CAnimatedMesh.cpp ../../EventHandler.cpp ../../FileHelpers.cpp \
		  ../../Game.cpp ../../IDevice.cpp ../../IMesh.cpp ../../InputDevice.cpp ../../Logger.cpp ../../MeshLoaders.cpp ../../Texture.cpp \
		  ../../Timer.cpp
# Sources for Linux build
LINUXSRC = ../../LinuxHelpers.cpp ../../CLinuxDevice.cpp
# Sources for Windows build
WINSRC = ../../WindowsHelpers.cpp ../../CWinDevice.cpp
# Sources for OSX build
OSXSRC = ../../OSXHelpers.cpp ../../COSXDevice.cpp

linux:
	$(CXX) $(CXXFLAGS) $(LINUXCXXFLAGS) -c $(SOURCES)
	$(CXX) $(CXXFLAGS) $(LINUXCXXFLAGS) -c $(LINUXSRC)
	
	$(RM) $(LINUXPROG)
	$(LD) $(LINUXLDFLAGS) *.o -o $(LINUXPROG)
	
	$(RM) *.o
	
windows:
	$(CXX) $(CXXFLAGS) $(WINCXXFLAGS) -c $(SOURCES)
	$(CXX) $(CXXFLAGS) $(WINCXXFLAGS) -c $(WINSRC)
	
	$(RM) $(WINPROG)
	$(LD) *.o -o $(WINPROG) $(WINDOWSLDFLAGS)
	
	$(RM) *.o

osx:
	$(CXX) $(CXXFLAGS) $(OSXCXXFLAGS) -c $(SOURCES)
	$(CXX) $(CXXFLAGS) $(OSXCXXFLAGS) -c $(OSXSRC)
	
	$(RM) $(OSXPROG)
	$(LD) $(OSXLDFLAGS) *.o -o $(OSXPROG)
	
	$(RM) *.o

clean:
	$(RM) $(LINUXPROG) $(WINPROG) $(OSXPROG) *.o
